using System;

using System.Xml;

using System.Data;
using Aulac.Global.Enums; using Aulac.Global.Data; using Aulac.Global.Common; using Aulac.Global.Xml;
using Aulac.Rsc.Bss;
using Aulac.Rsc.Bss.Tags;
using System.Windows.Forms;
using System.Collections.Generic;
using Aulac.Verb.Ems;
using Aulac.Global.AccessRight;

namespace Aulac.Client.Controls.Forms.Bss
{
	/// <summary>
	/// Summary description for DataCommon.
	/// </summary>
    public class DataHelper
	{
        public static AccessRights GetAccessRightFromSrv(string UserName, string moduleID)
        {
            try
            {
                AccessRights accRight = null;

               
                XmlDataDocument xmlDoc = Aulac.Client.Global.Member.GlobalMember.AulacConnectSrv.CreateXmlDocument(AulacEmsVerb.System.GetAccessRight, AulacEmsVerb.System.Noun.System);
                XmlProcess.AddValueParamItem(xmlDoc, tagSystem.Users.UserName, UserName);
                XmlProcess.AddValueParamItem(xmlDoc, tagSystem.Users.ModuleID, moduleID);
                xmlDoc = Aulac.Client.Global.Member.GlobalMember.AulacConnectSrv.ProcessRequest(xmlDoc);

                XmlElement eLine = XmlProcess.GetVchLineItemFirstElm(xmlDoc);
                accRight = new AccessRights();
                accRight.ModuleID = moduleID;

                if (eLine == null) return accRight;
                accRight.IsAdministrator = bool.Parse(eLine.GetAttribute(tagSystem.Users.IsSystem));
                accRight.IsAdd = bool.Parse(eLine.GetAttribute(tagSystem.Users.IsAdd));
                accRight.IsEdit = int.Parse(eLine.GetAttribute(tagSystem.Users.IsEdit)) == 1;
                accRight.IsEditBeforPrint = int.Parse(eLine.GetAttribute(tagSystem.Users.IsEdit)) == 2;
                accRight.IsDelete = int.Parse(eLine.GetAttribute(tagSystem.Users.IsDelete)) == 1;
                accRight.IsDeleteBeforPrint = int.Parse(eLine.GetAttribute(tagSystem.Users.IsDelete)) == 2;
                accRight.IsPrint = bool.Parse(eLine.GetAttribute(tagSystem.Users.IsPrint));
                accRight.IsShow = int.Parse(eLine.GetAttribute(tagSystem.Users.IsShow)) == 1;
                accRight.IsShowByUser = int.Parse(eLine.GetAttribute(tagSystem.Users.IsShow)) == 2;
                return accRight;
            }
            catch
            {
                return new AccessRights();
            }
        }

	
	}
}
